﻿package net.wangit.view.report;

import java.io.ByteArrayOutputStream;
import java.io.OutputStream;

import javax.servlet.http.HttpServletResponse;

import net.sf.jasperreports.engine.JRAbstractExporter;
import net.sf.jasperreports.engine.JRExporterParameter;
import net.sf.jasperreports.engine.export.JRPdfExporter;

public class PdfReportExporter
	implements ReportExporter
{

	public PdfReportExporter()
	{
	}

	public JRAbstractExporter createExporter()
	{
		return new JRPdfExporter();
	}

	public void export(JRAbstractExporter exporter, HttpServletResponse response)
		throws Exception
	{
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, baos);
		exporter.exportReport();
		byte bytes[] = baos.toByteArray();
		response.setContentType("application/pdf");
		response.setContentLength(bytes.length);
		OutputStream out = response.getOutputStream();
		out.write(bytes);
		out.flush();
	}
}
